﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Nhom14_HTTTHD_BuyMe
{
    public partial class delivery : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            int idtr = Convert.ToInt32(Request.QueryString["id"]);
            int idbid = 0;
            int t_bid = 0;
            int id_mua = 0;
            int id_ban = 0;
            int idPro = 0;
            using (websitebrokenEntities context = new websitebrokenEntities())
            {
                transaction t = (from x in context.transactions
                                 where x.id == idtr
                                 select x).FirstOrDefault();
                if (t != null)
                {
                    idbid = Convert.ToInt32(t.id_bid);
                    t_bid = Convert.ToInt32(t.type_bid);
                    info.Text = t.information;
                    sotien.Text = t.total.ToString();
                }
            }

            if (t_bid == 1)
            {
                using (websitebrokenEntities context = new websitebrokenEntities())
                {
                    bid_website t = (from x in context.bid_website
                                     where x.id == idbid
                                     select x).FirstOrDefault();
                    if (t != null)
                    {
                        id_mua = Convert.ToInt32(t.id_account);
                        idPro = Convert.ToInt32(t.id_website);
                    }
                }
                using (websitebrokenEntities context = new websitebrokenEntities())
                {
                    website t = (from x in context.websites
                                     where x.id == idPro
                                     select x).FirstOrDefault();
                    if (t != null)
                    {
                        id_ban = Convert.ToInt32(t.id_account);

                    }
                }
            }
            else if (t_bid == 2)
            {
                using (websitebrokenEntities context = new websitebrokenEntities())
                {
                    bid_domain t = (from x in context.bid_domain
                                     where x.id == idbid
                                     select x).FirstOrDefault();
                    if (t != null)
                    {
                        id_mua = Convert.ToInt32(t.id_account);
                        idPro = Convert.ToInt32(t.id_domain);
                    }
                }
                using (websitebrokenEntities context = new websitebrokenEntities())
                {
                    domain t = (from x in context.domains
                                 where x.id == idPro
                                 select x).FirstOrDefault();
                    if (t != null)
                    {
                        id_ban = Convert.ToInt32(t.id_account);

                    }
                }
            }

            mua.Text = id_mua.ToString();
            ban.Text = id_ban.ToString();

        }

        // chuyển hàng
        protected void btnGiaoHang_Click(object sender, EventArgs e)
        {
            // chuyen tien cho nguoi ban
             int idtr = Convert.ToInt32(Request.QueryString["id"]);
            string SID = "VU";
            string address = "http://localhost:49744/WebService1.asmx";
            string function = "paymentEndTransaction";

            int par1 = 1;
            int par2 = Convert.ToInt32(ban.Text);
            float par3 = (float)Convert.ToDouble(sotien.Text);
            string par4 = "đã chuyển " + par3.ToString() + "vao tài khoản của bạn cho cuôc giao dịch mã:" + idtr.ToString();
            int par5 = Convert.ToInt32(mua.Text);

            int res = (int)WebserviceInvoker.WSInvoker.CallWebService(address, "WebService1", function, new object[] { par1, par2, par3, par4, par5, idtr });
        }
    }
}